'use strict'

class review {

  constructor (mdb) {
    this.mdb = mdb || null
  }

  async get (c) {
    try{
      let sql='select * from publish,users,review where publish.publishid=review.publishid and publish.uid=users.uid and review.reviewuserid=users.uid'
      let r=await this.mdb.query(sql)
      let result=r['rows']
      console.log('这是得到的动态具体内容',result)
      if(result.rowCount<=0){
        return ('failed register',400)
      }
      return result

    }catch(e){
      return ('failed',400)
    }
  }
  async insert(c) {
    let data=JSON.parse(c)    
    let sql='select * from review';
    let r=await this.mdb.query(sql);
    let reviewid=r['rows'].length+1; 
    this.mdb.connect().then(client=>{
      client.query('insert into review values($1::int,$2::int,$3::varchar(20),$4::text,$5::text)',[data.publishid,reviewid,data.reviewuserid,data.reviewusername,data.reviewuserimg,reviewusercontent]).then(res=>{
        
      })
    })
    return 'insert review success'
    
  }

}

module.exports = review
